package com.android.hedgehog;

import java.util.List;

import android.graphics.Color;
import com.android.hedgehog.framework.Game;
import com.android.hedgehog.framework.Graphics;
import com.android.hedgehog.framework.Screen;
import com.android.hedgehog.framework.Input.TouchEvent;

public class FreePlayMenu2 extends Screen {
	enum Page {
		Page1, Page2
	}

	public Graphics graphics;
	Page currentPage;
	int gameNumber;

	public FreePlayMenu2(Game game) {
		super(game);
		graphics = game.getGraphics();
		currentPage = Page.Page1;
	}

	@Override
	public void update(float deltaTime) {
		List<TouchEvent> touchEvents = game.getInput().getTouchEvents();
		game.getInput().getKeyEvents();

		if (currentPage == Page.Page1)
			updatePage1(touchEvents);
		if (currentPage == Page.Page2)
			updatePage2(touchEvents);
	}

	private void updatePage1(List<TouchEvent> touchEvents) {
		int len = touchEvents.size();
		for (int i = 0; i < len; i++) {
			TouchEvent event = touchEvents.get(i);
			if (event.type == TouchEvent.TOUCH_UP) {

				if (event.y > 5 && event.y < 75) {
					playSound(1);
					game.setScreen(new ModeMenu(game,0));
				}
				if (event.y > 85 && event.y < 155) {
					playSound(1);
					game.setScreen(new ModeMenu(game,1));
				}
				if (event.y > 165 && event.y < 235) {
					playSound(1);
					game.setScreen(new ModeMenu(game,2));

				}
				if (event.y > 245 && event.y < 320) {
					game.setScreen(new ModeMenu(game,3));

				}
				if (event.y > 330 && event.y < 400) {
					game.setScreen(new ModeMenu(game, 4));
				}

				if (event.x < 50 && event.y > 430) { // if back button
					playSound(1);
					game.setScreen(new MainMenu2(game));
					return;
				}
				if (event.x > 270 && event.y > 430) { // if Forward button
					playSound(1);
					currentPage = Page.Page2;
					return;
				}

			}// TOUCH_UP
		}

	}

	private void updatePage2(List<TouchEvent> touchEvents) {
		int len = touchEvents.size();
		for (int i = 0; i < len; i++) {
			TouchEvent event = touchEvents.get(i);
			if (event.type == TouchEvent.TOUCH_UP) {

				if (event.y > 5 && event.y < 75) {

				}
				if (event.y > 85 && event.y < 155) {

				}
				if (event.y > 165 && event.y < 235) {

				}
				if (event.y > 245 && event.y < 320) {

				}
				if (event.y > 330 && event.y < 400) {

				}

				if (event.x < 50 && event.y > 430) { // if back button
					playSound(1);
					currentPage = Page.Page1;
					return;
				}
			}// TOUCH_UP
		}

	}


	@Override
	public void present(float deltaTime) {
		graphics.drawBackground(Color.BLACK);

		if (currentPage == Page.Page1) {// PAGE 1
			for (int i = 0; i < 5; i++) {
				graphics.drawUniversalRect(0, 5 + (80 * i), 319, 70, false, false, 4, 255, Color.RED); // rectangle
				graphics.drawUniversalLine(70, 5 + (80 * i), 70, 75 + (80 * i), 4, Color.RED);
				if (i == 0) {
					graphics.drawUniversalText("MATH", 2, true, 200, 60, 40, 255, Color.BLUE);
				}
				if (i == 1) {
					graphics.drawUniversalText("CARD", 2, true, 200, 140, 40, 255, Color.MAGENTA);
				}
				if (i == 2) {
					graphics.drawUniversalText("GOALIE", 2, true, 200, 220, 40, 255, Color.GREEN);
				}
				if (i == 3) {
					graphics.drawUniversalText("TIMEBOMB", 2, true, 200, 300, 40, 255, Color.YELLOW);
				}
				if (i == 4) {
					graphics.drawUniversalText("SEESAW", 2, true, 200, 380, 40, 255,
							Color.argb(255, 244, 164, 96));
				}

			}

			graphics.drawRect(0, 430, 50, 50, Color.WHITE); // back
			graphics.drawRect(270, 430, 50, 50, Color.WHITE); // forward

		} // PAGE 1

		if (currentPage == Page.Page2) {// PAGE 2

			for (int i = 0; i < 3; i++) {
				graphics.drawUniversalRect(0, 5 + (80 * i), 319, 70, false, false, 4, 255, Color.RED); // rectangle
				graphics.drawUniversalLine(70, 5 + (80 * i), 70, 75 + (80 * i), 4, Color.RED);
				if (i == 0) {
					graphics.drawUniversalText("?????", 2, true, 200, 60, 40, 255, Color.BLUE);
				}
				if (i == 1) {
					graphics.drawUniversalText("?????", 2, true, 200, 140, 40, 255, Color.MAGENTA);
				}
				if (i == 2) {
					graphics.drawUniversalText("?????", 2, true, 200, 220, 40, 255, Color.GREEN);
				}
			}

			graphics.drawRect(0, 430, 50, 50, Color.WHITE); // back

		} // PAGE 2

		

	}

	private void playSound(int soundNum) {
		if (!Settings.soundEnabled)
			return;
		if (soundNum == 1)
			Assets.bitten.play(1);

	}

	@Override
	public void pause() {

	}

	@Override
	public void resume() {

	}

	@Override
	public void dispose() {

	}

}
